import request from '../utils/request'

// 用户认证相关接口
export const login = (data) => {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  })
}

export const register = (data) => {
  return request({
    url: '/auth/register',
    method: 'post',
    data
  })
}

// 挂号相关接口
export const createRegistration = (data) => {
  return request({
    url: '/business/registration',
    method: 'post',
    data
  })
}

export const getMyRegistrations = () => {
  return request({
    url: '/business/my-registrations',
    method: 'get'
  })
}

export const cancelRegistration = (registrationId) => {
  return request({
    url: `/business/registration/${registrationId}/cancel`,
    method: 'post'
  })
}

// 就诊记录相关接口
export const getMedicalRecords = () => {
  return request({
    url: '/business/medical-records',
    method: 'get'
  })
}

export const getMedicalRecordDetail = (id) => {
  return request({
    url: `/business/medical-record/${id}`,
    method: 'get'
  })
}

// 药方相关接口
export const getPrescriptions = () => {
  return request({
    url: '/business/prescriptions',
    method: 'get'
  })
}

export const getPrescriptionDetail = (id) => {
  return request({
    url: `/business/prescription/${id}`,
    method: 'get'
  })
}

// 病房相关接口
export const getMyWardInfo = () => {
  return request({
    url: '/business/my-ward',
    method: 'get'
  })
}

// 个人信息相关接口
export const getUserProfile = () => {
  return request({
    url: '/patient/info',
    method: 'get'
  })
}

export const updateUserProfile = (data) => {
  return request({
    url: '/patient/updateUserInfo',
    method: 'put',
    data
  })
}

// 公告相关接口
export const getAnnouncements = (params) => {
  return request({
    url: '/business/announcements',
    method: 'get',
    params
  })
}

export const getAnnouncementDetail = (id) => {
  return request({
    url: `/business/announcement/${id}`,
    method: 'get'
  })
}

// 科室相关接口
export const getDepartments = (params) => {
  return request({
    url: '/business/departments',
    method: 'get',
    params: { ...params, isTree: true }
  })
}

export const getDepartmentDetail = (id) => {
  return request({
    url: `/business/department/${id}`,
    method: 'get'
  })
}

// 医生相关接口
export const getDoctorsByDepartment = (departmentId) => {
  return request({
    url: `/business/department/${departmentId}/doctors`,
    method: 'get'
  })
}

// 排班相关接口
export const getDoctorSchedules = (params) => {
  return request({
    url: '/business/schedules',
    method: 'get',
    params
  })
}

// 获取科室树形列表
export const getDepartmentTree = () => {
  return request({
    url: '/business/departments',
    method: 'get',
    params: { tree: true }
  })
}

// 提交挂号预约
export const makeAppointment = (data) => {
  return request({
    url: '/business/registration',
    method: 'post',
    data
  })
}

// 获取我的就诊记录
export const getMyMedicalRecords = () => {
  return request({
    url: '/business/my-medical-records',
    method: 'get'
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return request({
    url: '/user/info',
    method: 'get'
  })
}

// 更新用户信息
export const updateUserInfo = (data) => {
  return request({
    url: '/user/info',
    method: 'put',
    data
  })
}

// 获取科室列表
export const getDepartmentsList = () => {
  return request({
    url: '/departments',
    method: 'get'
  })
}

// 获取医生列表
export const getDoctors = (params) => {
  return request({
    url: '/doctors',
    method: 'get',
    params
  })
}

// 获取医生详情
export const getDoctorDetail = (id) => {
  return request({
    url: `/doctors/${id}`,
    method: 'get'
  })
}

// 获取医生排班
export const getDoctorSchedule = (doctorId, params) => {
  return request({
    url: `/doctors/${doctorId}/schedule`,
    method: 'get',
    params
  })
}

// 获取我的挂号列表
export const getMyRegistrationsList = (params) => {
  return request({
    url: '/registrations/my',
    method: 'get',
    params
  })
}

// 取消挂号
export const cancelRegistrationList = (id) => {
  return request({
    url: `/registrations/${id}/cancel`,
    method: 'put'
  })
}

// 获取我的就诊记录列表
export const getMyMedicalRecordsList = (params) => {
  return request({
    url: '/medical-records/my',
    method: 'get',
    params
  })
}

// 获取公告列表
export const getAnnouncementsList = (params) => {
  return request({
    url: '/announcements',
    method: 'get',
    params
  })
}

// 获取公告详情
export const getAnnouncementDetailList = (id) => {
  return request({
    url: `/announcements/${id}`,
    method: 'get'
  })
}

// 头像上传
export const uploadAvatar = (data) => {
  return request({
    url: '/patient/avatar',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

// 获取可预约时间段
export const getAvailableSchedules = (params) => {
  return request({
    url: '/business/schedules/available',
    method: 'get',
    params
  })
}

// 修改密码
export const changePassword = (data) => {
  return request({
    url: '/auth/password',
    method: 'put',
    data
  })
} 